/*Diego Lima de Freitas RA: 317632
 *Yuri Souza Padua RA: 317420
 * 
 * Classe que trata o comando for
 */
package AST;

public class ForCommand extends Command {

    private VarDec forVariable;
    private Expr exprStart, exprEnd;
    private Command command;

    public ForCommand(VarDec forVariable, Expr exprStart, Expr exprEnd, Command command) {
        this.forVariable = forVariable;
        this.exprStart = exprStart;
        this.exprEnd = exprEnd;
        this.command = command;
    }

    @Override
    public void genC(PW pw) {
        pw.print("for ( " + forVariable.getName() + " = ");
        exprStart.genC(pw, false);
        pw.out.print("; " + forVariable.getName() + " <= ");
        exprEnd.genC(pw, false);
        pw.out.println("; " + forVariable.getName() + "++ ) ");
        if (command != null) {
            if (command instanceof CompositeCommand) {
                command.genC(pw);
            } else {
                pw.add();
                command.genC(pw);
                pw.sub();
                //pw.println("}");
            }
        }
    }
}